/*
Copyright (C) 2015 Jochem Raat

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <heatMap.h>
#include <normalizer.h>

double *HeatMapGenerator::generateHeatMap(double *heightMap,
                                          unsigned width,
                                          unsigned height)
{                               // Doesnt work yet, because the height
                                // map doesn't have a good size
    double *fractalMap;
    int passes = 9;
    double values[9*2] = {
        512.0, 0.5,
        256.0, 0.8,
        128.0, 0.6,
        64.0,  0.4,
        32.0,  0.2,
        16.0,  0.08,
        8.0,   0.02,
        4.0,   0.003,
        2.0,   0.0001};

    fractalNoiseGenerator
        .generateFractalNoiseFromValues(values, passes * 2,
                                        width, height);

    fractalMap = fractalNoiseGenerator.noiseMap;

    double *heatMap = new double[width * height];

    for (int i = 0; i < (width * height); i++) {
        heatMap[i] = generateHeatPoint(heightMap[i], fractalMap[i]);
    }

    Normalizer<double>::normalize(heatMap, heatMap, width * height,
                                  0.0, 1.0);

    return heatMap;
}

double HeatMapGenerator::generateHeatPoint(double height,
                                           double noise)
{
    // The lower the hotter
    double heat = noise - (height * 10);
    return heat;
}
